﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Data.SqlClient;
using System.Data;

namespace DataAccess_Layer
{
    public static class BonusList_Dac
    {
        public static bool insert(long prodID, string bonusIDs)
        {
            List<SqlParameter> sqlParams = makeInsertParams(prodID, bonusIDs);

            DataAccessHelper helper = null;
            SqlDataReader rdr = null;
            int count;
            try
            {
                helper = new DataAccessHelper();
                rdr = helper.excuteSP("SP_Insert_Bonus_List", sqlParams);
            }
            finally
            {
                helper.close();
                rdr.Close();

                // If your Command contains output parameters or return values, they will not be available until the DataReader is closed.            
                count = (int)sqlParams[sqlParams.Count - 1].Value;
            }

            return (count == 1);
        }

        private static List<SqlParameter> makeInsertParams(long prodID, string bonusIDs)
        {
            List<SqlParameter> sqlParams = new List<SqlParameter>();

            SqlParameter inParam = new SqlParameter("@prodID", SqlDbType.BigInt);
            inParam.Direction = ParameterDirection.Input;
            inParam.Value = prodID;
            sqlParams.Add(inParam);

            inParam = new SqlParameter("@bonusIds", SqlDbType.VarChar, 1000);
            inParam.Direction = ParameterDirection.Input;
            inParam.Value = bonusIDs;
            sqlParams.Add(inParam);

            return sqlParams;
        }
    }
}
